<template>
  <div>
    <input type="text" v-model="content" ></input>
    <button type="button" @click="send" >发送</button>
  </div>

</template>

<script>


 let ws = new WebSocket("ws://47.105.38.53:8282")
//let ws = new WebSocket("wss://bjyoupei.techbz.cn:8282")

export default {
  name: "demo",

  data(){
    return{
      content:'',
      clientId:''
    }
  },

  methods:{

    send(){
      const msg = this.content
      console.log('开始发送')
      this.$myHttpGet('/guard/send',{clientId:this.clientId,msg:msg}).then(res=>{
        console.log('开始完成')
        if(res.status){
          //alert(res.msg)
        }
      })
    },
    open3(msg) {
      this.$notify.info({
        title: '消息',
        message: '这是一条消息的提示消息---'+msg,
        onClick:function (){
          alert(msg)
          this.close()
        }
      });
    },

  },

  mounted() {
    ws.onmessage = (e)=>{
      console.log(e.data)
      let data = JSON.parse(e.data)
      console.log(data)
      if(data.type=='init'){
        this.clientId = data.client_id
        this.$myHttpGet('/guard/demo',{clientId:data.client_id,msg:"我是workman"})
      }else if(data.type=='say'){

        this.open3(data.msg)

        //console.log(data)
      }else{
        console.log('未知的消息类型')
      }
    }


  }

}
</script>

<style scoped>

</style>
